package com.yonder.hashmaptest;

/**
 * 
 * 2017年9月6日
 * 
 */
public class DebugTools {
	public static void printStack() {
		StackTraceElement[] st = Thread.currentThread().getStackTrace();
		if (st == null) {
			System.out.println("无堆栈...");
			return;
		}
		StringBuffer sbf = new StringBuffer();
		for (StackTraceElement e : st) {
			if (sbf.length() > 0) {
				sbf.append(" <- ");
				sbf.append(System.getProperty("line.separator"));
			}
			sbf.append(java.text.MessageFormat.format("{0}.{1}() {2}", e.getClassName(), e.getMethodName(),
					e.getLineNumber()));
		}
		System.out.println(sbf.toString());
	}
	
	static double lastMem = 0;
	
	public static void printMemUsed(){
		try {
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}//等待GC回收
		System.out.println("内存使用量为:" + (-lastMem+(lastMem=(Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory()) / 1000d / 1000))+"M");
	}

}
